{include file="public/header"/}
<link rel="stylesheet" href="{__PUBLIC_PATH}/admin/pcf/pcfbase.css?v={$version}"/>
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/ueditor.config.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/ueditor.all.min.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/common/plugins/Ueditor/lang/zh-cn/zh-cn.js?v={$version}"></script>
</head>
<body>
<style type="text/css" media="screen">
  .pcfts{font:bold 14px/20px tahoma,verdana;color:#F60;vertical-align:middle;display:inline-block;margin-right:5px;margin-left:-14px;}
  .layui-table{width:100%!important;}
  .layui-table-cell{height:auto!important;}
  @media screen and (max-width:800px){
      .layui-table-cell{width:250px!important;padding:0!important;}
  }
  .layui-table select {border-color:#e6e6e6;height:28px;}
</style>
<div class="layui-form" id="LAY-component-layer-list">
<div class="layui-fluid" style="padding-bottom:83px;border:0;">
<div class="layui-col-md12">
<div class="layui-card" style="box-shadow:none;">
  <div class="layui-tab layui-tab-card" style="box-shadow:none;">
    <ul class="layui-tab-title">
      <li class="layui-this">常规选项</li>
      <li>高级选项</li>
    </ul>
    <div class="layui-tab-content">
      <div class="layui-tab-item layui-show">
        <div class="layui-row">
          <div class="layui-col-md5">
              <div class="layui-form-item">
                  <label class="layui-form-label"><b class="pcfts">*</b> 栏目名称</label>
                  <div class="layui-input-block">
                   <input type="text" name="typename" id="typename" value="" lay-verify="required" class="layui-input">
                  </div>
              </div>
              <div class="layui-form-item">
                  <label class="layui-form-label">目录名称</label>
                  <div class="layui-input-block">
                   <input type="text" value="" name="dirname" id="dirname" class="layui-input" lay-verify="check_dirname" onkeyup="this.value=this.value.replace(/[^a-zA-Z0-9_]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/\[^a-zA-Z0-9_]/g,''));">
                  </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label"><b class="pcfts">*</b> 内容模型</label>
                <div class="layui-input-inline">
                 <select name="current_channel" id="current_channel" lay-verify="required" lay-filter="current_channel">
                    {volist name="channeltype_list" id="vo"}
                    <option value="{$vo.id}" data-nid="{$vo.nid}" {eq name="$current_channel" value="$vo.id"}selected="true"{/eq}>{$vo.title}</option>
                    {/volist}
                  </select>
                  <div class="layui-form-inline2" style="margin-left:0px;" id="notic_current_channel"></div>
                </div>
              </div>
              {gt name="$parent_id" value="0"}
              <div class="layui-form-item">
                <label class="layui-form-label">所属栏目</label>
                <div class="layui-input-inline">
                    <div style="line-height:38px;">{$ptypename|default=''}</div>
                </div>
              </div>
              {/gt}
              <div class="layui-form-item none">
                <label class="layui-form-label">文件保存目录</label>
                <div class="layui-input-inline">
                    <input type="text" value="{$predirpath}" name="dirpath" id="dirpath" class="layui-input" onkeyup="this.value=this.value.replace(/[^0-9a-zA-Z\/-]/g,'');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^0-9a-zA-Z\/-]/g,''));">
                </div>
              </div>
              <div class="layui-form-item">
                <label class="layui-form-label">隐藏栏目</label>
                <div class="layui-input-inline">
                    <input type="checkbox" lay-filter="is_hidden" lay-skin="switch" lay-text="是|否">
                    <input type="hidden" name="is_hidden" value="0" />
                </div>
              </div>

              {include file="channel/field/addonitem"/}
          </div>
        </div>
      </div>

      <div class="layui-tab-item">
        <div class="layui-row">
          <div class="layui-col-md5">

              <div class="layui-form-item">
                <label class="layui-form-label">外部链接</label>
                <div class="layui-input-inline">
                    <input type="checkbox" lay-filter="is_part" lay-skin="switch" lay-text="开启|关闭">
                    <input type="hidden" name="is_part" value="0" />
                </div>
              </div>

              <div class="layui-form-item none" id="is_part1">
                <label class="layui-form-label"><b class="pcfts">*</b>URL网址</label>
                <div class="layui-input-block">
                  <input type="text" name="typelink" value="" lay-verify="check_typelink" placeholder="http://" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label">英文别名</label>
                <div class="layui-input-block">
                  <input type="text" name="englist_name" value="" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                  <label class="layui-form-label">栏目图片</label>
                  <div class="layui-input-block">
                  <ul class="layout">
                    <li style="margin-right:10px;">
                    <input name="litpic" id="litpic" placeholder="图片地址" value="" class="layui-input inp inp_logo">
                    <img id="img_litpic" src="{:get_default_pic()}" class="pcfdisplay">
                    </li>
                    <li style="margin-top:3px;">
                      <div class="layui-btn-group">
                        <input type="button" value="上传图片" class="layui-btn layui-btn-sm test-upload-demoMore" lay-data="{number:1,ey_inputId:'litpic',ey_savepath:'allimg'}">
                        <input type="button" value="选择图片" class="layui-btn layui-btn-sm" onClick="GetPictureFolder(1,'litpic');">
                        <input type="button" value="预览" class="layui-btn layui-btn-sm" onclick="BigImages($('#img_litpic').attr('src'));">
                        <input type="button" value="清除" class="layui-btn layui-btn-sm layui-btn-warm" data-inputid="litpic" onclick="DelImages(this);">
                      </div>
                    </li>
                  </ul>
                </div>
              </div>

              <div class="layui-form-item" id="dl_templist">
                <label class="layui-form-label" for="templist"><b class="pcfts">*</b>列表模板</label>
                <div class="layui-input-inline">
                   <select name="templist" id="templist" lay-verify="check_templist">
                  </select>
                </div>
                <div class="layui-input-inline layui-btn-container">
                  <div class="layui-form-inline2 ">列表模板命名规则：<br/>lists_<font class="font_nid">模型标识</font>.html<br/>lists_<font class="font_nid">模型标识</font>_自定义.html</div>
                </div>
                 <div class="layui-input-inline layadmin-layer-demo" style="margin-top:3px;">
                   <a class="layui-btn layui-btn-sm" data-value="lists" data-type="newtpl">新建模板</a>
                </div>
              </div>

              <div class="layui-form-item" id="dl_tempview">
                <label class="layui-form-label" for="tempview"><b class="pcfts">*</b>文档模板</label>
                <div class="layui-input-inline">
                   <select name="tempview" id="tempview" lay-verify="check_tempview">
                  </select>
                </div>
                <div class="layui-input-inline layui-btn-container">
                  <div class="layui-form-inline2 ">文档模板命名规则：<br/>view_<font class="font_nid">模型标识</font>.html<br/>view_<font class="font_nid">模型标识</font>_自定义.html</div>
                </div>
                 <div class="layui-input-inline layadmin-layer-demo" style="margin-top:3px;">
                   <a class="layui-btn layui-btn-sm" data-value="view" data-type="newtpl">新建模板</a>
                </div>
              </div>

              <div class="layui-form-item">
                <label class="layui-form-label">SEO标题</label>
                <div class="layui-input-block">
                  <input type="text" name="seo_title" value="" class="layui-input">
                </div>
              </div>  

              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">SEO关键字</label>
                <div class="layui-input-block">
                  <textarea name="seo_keywords" class="layui-textarea"></textarea>
                </div>
              </div>

              <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">SEO描述</label>
                <div class="layui-input-block">
                  <textarea name="seo_description" class="layui-textarea"></textarea>
                </div>
              </div>
              <input type="hidden" name="grade" id="grade" value="{$grade|default='0'}">
              <input type="hidden" name="parent_id" id="parent_id" value="{$parent_id|default=''}" />

          </div>
        </div>
      </div>
      <div class="pcfclear"></div>
    </div>
  </div>
</div>
</div>
<div class="submit-info text-center">
    <button class="layui-btn" lay-submit lay-filter="formSubmit">确认提交</button>
    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
</div>
<div class="pcfclear"></div>
</div>
</div>
{include file="public/footer"/}
<script>
layui.use(['layer', 'form', 'table', 'util', 'admin','element'], function () {
    var $ = layui.$,
    element = layui.element,
    router = layui.router(),
    layer = layui.layer,
    form = formNew = layui.form;
    element.render();
    var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    var templateList = {$templateList|raw};
    ajax_get_template();

    form.verify({
      check_typename: function(value, item){
        if(value == '' || undefined == value){
            tabchange(0)
            return '必填项不能为空';
        }
      },
      check_dirname: function(value, item){
        var patrn = /^\d+$/;
        if (patrn.test(value) == true) {
            tabchange(0)
            return '目录名称不能为纯数字！';
        }
      },
      check_typelink: function(value, item){
        if ($('input[name=is_part]').val() == 1) {
            if(value == ''){
                tabchange(1);
                return '外部链接不能为空！';
            }
        }
      },
      check_templist: function(value, item){
        if(value == '' || undefined == value){
            tabchange(1)
            return '请选择列表模板';
        }
      },
      check_tempview: function(value, item){
        var channel = parseInt($('#current_channel').find('option:selected').val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        if($('#tempview').val() == '' && $.inArray(channel, js_allow_channel_arr) != -1){
            tabchange(1)
            return '请选择文档模板';
        }
      }
    }); 

    function tabchange(tabIndex){
        var tabObj = $('div.layui-tab ul.layui-tab-title');
        tabObj.find('li').each(function(){
            $(this).removeClass('layui-this');
        });
        $(tabObj.find('li').get(tabIndex)).addClass('layui-this');
        $('.layui-tab-item').removeClass('layui-show');
        $($('.layui-tab-item').get(tabIndex)).addClass('layui-show');
    }

    // 监听开关
    form.on('switch', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
      } else {
        this.value = 0;
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    // 监听开关
    form.on('switch(is_part)', function(data){
      var elemId = data.elem.attributes['lay-filter']['nodeValue'];
      if (data.elem.checked) {
        this.value = 1;
        $('#is_part1').show();
      } else {
        this.value = 0;
        $('#is_part1').hide();
      }
      $("input[name='"+elemId+"']").val(this.value);
    });

    form.on('select(current_channel)', function(data){
        ajax_get_template();
    });

    //触发事件
    var active = {
      newtpl: function(){
        var type = $(this).data('value');
        var nid = $('#current_channel').find('option:selected').attr('data-nid');
        var url = "{:url('/arctype/ajax_newtpl')}";
        if (url.indexOf('?') > -1) {
            url += '&';
        } else {
            url += '?';
        }
        url += 'type='+type+'&nid='+nid;
        if ('lists' == type) {
            var title = '新建列表模板';
        } else {
            var title = '新建文档模板';
        }
        var iframes = layer.open({
            type: 2,
            title: title,
            fixed: true,
            shadeClose: false,
            shade: 0.3,
            area: ['90%', '90%'],
            content: url
        });
      }
    };

    $('#LAY-component-layer-list .layadmin-layer-demo .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] && active[type].call(this);
    });

    //监听提交
    form.on('submit(formSubmit)', function(data){
        layer.load(2);
        $.ajax({
            type : 'post',
            url : "{:url('/arctype/add')}",
            data : data.field,
            dataType : 'json',
            success : function(res){
                layer.closeAll('loading');
                if(res.status){
                    layer.msg(res.msg, {icon: 1, time: 1000}, function(){
                        parent.window.location.href = res.url;
                    });
                }else{
                    layer.msg(res.msg, {icon: 2, time: 1000});
                }
            },
            error: function(e){
                layer.closeAll('loading');
                layer.msg("未知错误，操作中断！", {icon: 2, time: 1000});
            }
        });
        return false;
    });

    function ajax_get_template() {
        var obj = $('#current_channel');
        var channel = parseInt($(obj).find('option:selected').val());
        var js_allow_channel_arr = {$js_allow_channel_arr};
        $('#notic_current_channel').html('');
        $.ajax({
            url: "{:url('/arctype/ajax_getTemplateList')}",
            type: 'GET',
            dataType: 'JSON',
            success: function(res){
                if (res.status) {
                    templateList = res.data.templateList;
                }
            }
        });
        if (templateList[channel] == undefined || templateList[channel] == '') {
            showErrorMsg('模板文件不存在！');
            return false;
        } else if (templateList[channel]['msg'] != '') {
            $('#notic_current_channel').html(templateList[channel]['msg']);
        }
        $('#templist').html(templateList[channel]['lists']);
        if ($.inArray(channel, js_allow_channel_arr) == -1) {
            if (channel == 6) {
                $('#dl_templist').find('label[for=templist]').html('<b class="pcfts">*</b>单页模板');
            }
            $('#dl_tempview').hide();
        } else {
            $('#dl_templist').find('label[for=templist]').html('<b class="pcfts">*</b>列表模板');
            $('#dl_tempview').show();
        }
        $('#tempview').html(templateList[channel]['view']);
        $('.font_nid').html(templateList[channel]['nid']);
        form.render();
        return false;
    }

  });
</script>
</body>
</html>